/*
 * OrderListItem.java
 * business
 *
 * Created by ChenTao on 2017/2/28.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.bean.Order;
import com.yidiandao.business.data.event.OrderEvent;
import com.yidiandao.business.ui.orderabout.order.OrderActivity;
import com.yidiandao.business.ui.orderabout.orderdetail.OrderDetailActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.OrderHolder;
import com.yidiandao.business.ui.widget.view.OrderButtonLayout;
import com.yidiandao.business.ui.widget.view.OrderGoodsInfoLayout;
import com.yidiandao.business.utils.UIUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/** 我的订单 未付款 */
public class OrderListItem extends DisplayListItem<OrderHolder, Order> {

    private OrderActivity mActivity;

    public OrderListItem(Order s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, OrderHolder holder) {
        mActivity = (OrderActivity) context;
        //订单id
        final String orderId = data.getOrderId();
        //订单编号
        holder.mTvOrderNum.setText(data.getOrderSn());
        //价格
        holder.mTvTotlePrice.setText(data.getTotalFee());
        //商品信息
        final List<Goods> goodsList = data.getGoodsList();
        holder.mInfoLayout.setData(goodsList);
        //几件商品
        holder.mTvTip.setText(UIUtils.getString(R.string.order_tip, data.getTotalCount()));

        //订单状态
        holder.mTvState.setText(data.getOrderStatus());
        List<String> buttons = data.getButtons();
        if (buttons != null && buttons.size() > 0) {
            holder.mOrderStatusView.setVisibility(View.VISIBLE);
            holder.mOrderStatusView.setData(mActivity, orderId, buttons, goodsList);
        } else {
            holder.mOrderStatusView.setVisibility(View.GONE);
        }
        holder.mOrderStatusView.setOnItemClickListener(
                new OrderButtonLayout.OnItemClickListener() {
                    @Override
                    public void onItemClick() {
                        EventBus.getDefault().post(new OrderEvent());
                    }
                });

        holder.mInfoLayout.setOnItemClickListener(
                new OrderGoodsInfoLayout.OnItemClickListener() {
                    @Override
                    public void onItemClick(int position, String goodsId) {
                        OrderDetailActivity.actionStart((Activity) context, data.getOrderId());
                    }
                });
        //查看订单信息
        holder.mLlList.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        OrderDetailActivity.actionStart((Activity) context, data.getOrderId());
                    }
                });
    }

    @Override
    public String getDisplayItemTag() {
        return OrderListItem.class.getSimpleName();
    }

    @Override
    public Class<OrderHolder> getViewHolderClazz() {
        return OrderHolder.class;
    }
}
